#!/usr/bin/env python
"""
get_info(): Get the amarok playing status.
If amarok isn't playing, get_info() will return None
"""
import os
from misc import status_dict

def _dcop_query(command):
    """
    Query dcop, using command. Return the resulting str.
    """
    pipe = os.popen(command)
    if not pipe:
        return ""
    s = pipe.read()
    pipe.close()
    return s.strip()

def _get(want_what):
    return _dcop_query("dcop amarok default %s" % want_what)

def get_info():
    """
    Return a dict of informations about the playing music.
    """
    info = {}
    info['status'] = status_dict.get(_get("status"))
    if info['status'] in ('NORMAL', 'PAUSED'):
        for elem in ('artist', 'album', 'title', 'totalTime', 'currentTime'):
            info[elem] = _get(elem)
        return info

if __name__ == "__main__":
    print get_info()
